package com.zy.web.demo.md5;

import java.security.MessageDigest;

/**
 * @author <a href="mailto:zhouyong@cqyyt.com">zy</a>
 * @version 1.0
 * @date 2020/9/21 14:44
 */
public class md5 {

    public static void main(String[] args) {

       try {
           String result = "";
           String str = "123456";

           MessageDigest md5 = MessageDigest.getInstance("MD5");
           md5.update((str).getBytes("UTF-8"));
           byte b[] = md5.digest();

           int i;
           StringBuffer buf = new StringBuffer("");

           for(int offset=0; offset<b.length; offset++){
               i = b[offset];
               if(i<0){
                   i+=256;
               }
               if(i<16){
                   buf.append("0");
               }
               buf.append(Integer.toHexString(i));
           }

           result = buf.toString();
           System.out.println(result.length());
           System.out.println("result = " + result);
       }catch (Exception e){
           e.printStackTrace();
       }

    }

}
